<?php
/**
 * Created by PhpStorm.
 * User: lawrence
 * Date: 01.06.2014
 * Time: 14:56
 */

class Find_Room extends  CI_Controller
{
    public function get_data()
    {
        $this->load->library('session');

        $location = $this->input->post('location_id');
        $floor = $this->input->post('floor_id');
        $rooms = $this->input->post('room_id');
        $rooms_1 = $this->input->post('room_count_one');
        $rooms_2 = $this->input->post('room_count_two');
        $orient = $this->input->post('geographic_id');
        $airVal = $this->input->post('air_cond');
        $tv = $this->input->post('tv_setup_list');
        $bar = $this->input->post('minibar_setup');
        $startDate = $this->input->post('start_date');
        $endDate = $this->input->post('end_date');

        $air = ($airVal == "1" ? 1 : 0);

        if($startDate == '')
        {
            $startDate = date('Y-m-d');
        }
        else
        {
            $startDate = date('Y-m-d', strtotime($startDate));
        }

        if($endDate == '')
        {
            $endDate = $startDate;
        }
        else
        {
            $endDate = date('Y-m-d', strtotime($endDate));
        }

        if($startDate > $endDate) $startDate = $endDate;

        $data['result'] = $this->Db_Model_Find->find_all($location, $floor, $rooms, $orient, $air, $tv, $bar, $rooms_1, $rooms_2, $startDate, $endDate);

        if(!is_array($data['result']))
        {
            $data['result'] = array();
        }

        $data['startdate'] = $startDate;
        $data['enddate'] = $endDate;

        $data['window'] = 'search';
        $data['pagetitle'] = 'Search Rooms';
        $this->load->view('header', $data);

        $this->load->view('results', $data);

        $this->load->view('footer');
    }
} 